package BufferedStream1;

import jdk.nashorn.internal.ir.WhileNode;

import java.io.*;

/**
 * @author: wuhao
 * @since: 2021/5/1 11:34
 */
public class BufferedReaderTest {

    public static void main(String[] args) {
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        try {
            //创建缓冲字符流-->处理流
            bufferedReader = new BufferedReader(new FileReader("D:\\test1\\作文1.txt"));
            bufferedWriter = new BufferedWriter(new FileWriter("D:\\test2\\作文2.txt"));

            String str;
            while ((str = bufferedReader.readLine()) != null) { //一次读取字符文本文件的一行字符
                bufferedWriter.write(str); //一次写入一行字符串
                bufferedWriter.newLine(); //写入行分隔符
            }
            bufferedWriter.flush();//刷新缓存区
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
            try {
                if (bufferedWriter != null) {
                    bufferedWriter.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}
